package org.example.config;

import org.example.filter.RequestApiSafeFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * Description:
 *
 * @author shenguangyang
 */
@Configuration
public class FilterConfig {

    @Bean
    public RequestApiSafeFilter getRequestApiSafeFilter() {
        return new RequestApiSafeFilter();
    }

    /**
     *
     * @return 过滤器bean
     */
    @Bean
    @Order(100)
    public FilterRegistrationBean<RequestApiSafeFilter> requestApiSafeFilter() {
        FilterRegistrationBean<RequestApiSafeFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        RequestApiSafeFilter requestApiSafeFilter = getRequestApiSafeFilter();
        filterRegistrationBean.setFilter(requestApiSafeFilter);
        // 配置过滤规则
        filterRegistrationBean.addUrlPatterns("/*");
        // 设置过滤器名称
        filterRegistrationBean.setName("requestApiSafeFilter");
        // 执行次序
        return filterRegistrationBean;
    }
}
